// -------- 加载配置 -------------
import {
    getFeature,
    subFeature,
    ParentFeature,
    subFeatureBeClick
} from '../setting/districtExplorer'

/**
 * 绘制行政区节点,单色彩
 * @param {*} districtExplorer
 * @param {*} areaNode
 * @param {*} map
 * @param subAdcode
 */
export function renderAreaNode(districtExplorer, areaNode, map, subAdcode = null) {

    //清除已有的绘制内容
    districtExplorer.clearFeaturePolygons();

    //绘制子级区划
    districtExplorer.renderSubFeatures(areaNode, function (feature) {

        if (feature.properties.adcode === subAdcode) {
            return subFeatureBeClick;
        }
        return subFeature;
    });

    //绘制父级区划，仅用黑色描边
    districtExplorer.renderParentFeature(areaNode, ParentFeature);

    //更新地图视野以适合区划面
    // map.setFitView(districtExplorer.getAllFeaturePolygons());
}

/**
 * 绘制行政区节点,多色彩
 * @param {*} districtExplorer
 * @param {*} areaNode
 * @param {*} colors
 * @param {*} map
 */
export function renderAreaNodeColors(districtExplorer, areaNode, colors, map) {

    //清除已有的绘制内容
    districtExplorer.clearFeaturePolygons();

    //绘制子级区划
    districtExplorer.renderSubFeatures(areaNode, function (feature, i) {

        var fillColor = colors[i % colors.length];

        var strokeColor = colors[colors.length - 1 - i % colors.length];


        return getFeature(strokeColor, fillColor);
    });

    //绘制父级区划，仅用黑色描边
    districtExplorer.renderParentFeature(areaNode, ParentFeature);

    //更新地图视野以适合区划面
    map.setFitView(districtExplorer.getAllFeaturePolygons());
}